package hadoop;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @author cheng
 * @date 2021/10/25 9:14
 */
public class WordcountReduce extends Reducer<Text, IntWritable,Text,IntWritable> {
    // 设置reduce端输出的类型
    int sum =0;
    IntWritable v = new IntWritable();

    // 快捷键 ： ctrl + o
    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        // 累计
        sum = 0 ;
        for (IntWritable count :values){
            sum += count.get();
        }
        v.set(sum);
        context.write(key,v);
    }
}
